package view;

import java.awt.Font;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;

import org.jdesktop.swingx.JXHyperlink;

import view.components.Icons;

import application.LibraryApp;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import control.ExportLoanRemindersAction;
import control.ExportLoanStatisticAction;
import control.NewBookAction;
import control.NewCustomerAction;
import control.NewLoanAction;
import control.OpenBookOverviewAction;
import control.OpenCustomerOverviewAction;
import control.OpenLoanOverviewAction;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

@SuppressWarnings("serial")
public class LibraryMainJPanel extends AbstractContentJPanel {
	public LibraryMainJPanel(){
		this(null);
	}
	
	public LibraryMainJPanel(LibraryMainJFrame mainFrame) {
		super(mainFrame);
		initGUI();
	}
	
	@Override
	public String getName(){
		return "Start";
	}
	
	@Override
	public Icon getIcon(){
		return Icons.HOME;
	}
	
	@Override
	public boolean isCloseable(){
		return false;
	}

	private void initGUI() {
		setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("default:grow"),
				ColumnSpec.decode("100dlu"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("100dlu"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("100dlu"),
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("default:grow"),
				FormFactory.DEFAULT_ROWSPEC,
				RowSpec.decode("40dlu"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("80dlu"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow(2)"),}));
		
		JLabel lblTitle = new JLabel(LibraryApp.TITLE);
		lblTitle.setFont(new Font("Tahoma", Font.BOLD, 20));
		lblTitle.setIcon(Icons.LIBRARY);
		add(lblTitle, "2, 2, 9, 1, center, default");
		
		JSeparator separator = new JSeparator();
		separator.setOrientation(SwingConstants.VERTICAL);
		add(separator, "4, 4, 1, 7");
		
		JSeparator separator_1 = new JSeparator();
		separator_1.setOrientation(SwingConstants.VERTICAL);
		add(separator_1, "8, 4, 1, 7");
		
		JButton btnBooks = new JButton(new OpenBookOverviewAction(mainFrame));
		add(btnBooks, "2, 5, default, fill");
		
		JButton btnCustomers = new JButton(new OpenCustomerOverviewAction(mainFrame));
		add(btnCustomers, "6, 5, default, fill");
		
		JButton btnLoans = new JButton(new OpenLoanOverviewAction(mainFrame));
		add(btnLoans, "10, 5, default, fill");
		
		JXHyperlink btnNewBook = new JXHyperlink(new NewBookAction(mainFrame));
		add(btnNewBook, "2, 7, left, fill");
		
		JXHyperlink btnNewCustomer = new JXHyperlink(new NewCustomerAction(mainFrame));
		add(btnNewCustomer, "6, 7, left, fill");
		
		JXHyperlink btnNewLoan = new JXHyperlink(new NewLoanAction(mainFrame));
		add(btnNewLoan, "10, 7, left, fill");
		
		JXHyperlink btnExportReminders = new JXHyperlink(new ExportLoanRemindersAction());
		add(btnExportReminders, "6, 9, left, default");
		
		JXHyperlink btnExportStatistics = new JXHyperlink(new ExportLoanStatisticAction());
		add(btnExportStatistics, "10, 9, left, default");
	}

}
